<template>
  <div id="box">
    <headerBar></headerBar>
    <div class="wraper">
      <div>重置密码</div>
      <div class="password">
        <input type="password" v-model="psd1" placeholder="密码">
      </div>
      <div class="confirm">
        <input type="password" v-model="psd2" placeholder="确认密码">
      </div>
      <div class="sure" @click="change_psd">确认</div>
    </div>
  </div>
</template>

<script>

  import headerBar from '@/public/header'

  export default {
    components:{
      headerBar
    },
    data () {
      return {
        //密码
        psd1:"",
        psd2:"",
      }
    },
    methods:{

      //提示框
      toastNone(msg) {
        this.$dialog.toast({
          mes: msg,
          timeout: 1500
        });
      },

      //修改登录密码
      change_psd:function () {
        let that = this;
        //密码不能为空
        if(!that.psd1){
          that.toastNone("密码不能为空");
        }
        //两次输入密码须一致
        if(that.psd1 !== that.psd2){
          that.toastNone("两次输入密码不一致");
        }

        //获取传值的对象
        let obj = JSON.parse(sessionStorage.obj);
        obj.login_password = Base64.encode(that.psd1);
        obj.login_password_level = "low";


        that.$http({
          method: 'post',
          url: domain.webUrl + "/exchange/v1/user/sign/app/reset/by/mobile",
          data:obj
        }).then((data)=>{
          that.toastNone(data.data.message);
          if(data.data.code === 0){
            sessionStorage.removeItem("obj");
            that.$router.push({path:'/login'});
          }
        }).catch((data)=>{
          that.toastNone("重置登录密码接口"+"出错");
        })
      }
    },
    created: function () {
      that.$router.push({path:'/login'});
    }
  }
</script>

<style lang="less" scoped>
  @import "../style/var.less";
  #box{
    .full;
    position: fixed;
    z-index: 1;
    background: #ffffff;
    .wraper{
      padding: 0 1rem;
      .full;
      .relative;
      div{
        &:nth-child(1){
          margin-top: 1.3rem;
          font-size: 0.58rem;
          color: #636363;
          margin-bottom: 1.1rem;
        }
      }
      .password{
        margin-bottom: 0.55rem;
        input{
          .full-w;
          border: none;
          font-size: 0.3rem;
          font-weight: 500;
        }
      }
      .confirm{
        input{
          .full-w;
          border: none;
          font-size: 0.3rem;
          font-weight: 500;
        }
      }
      .sure{
        margin-top: 2rem;
        font-size: 0.5rem;
        color:#ff9e01;
      }
    }
  }
</style>
